package cn.zxh.improvement.common.core.function;


import cn.zxh.improvement.common.core.utils.Exceptions;

/**
 * 断言
 *
 * @author zxh
 * @since 2023/4/26 15:51:22
 */
@FunctionalInterface
public interface PredicateWithException<T> extends java.util.function.Predicate<T> {

    /**
     * 断言结果
     *
     * @param arg 入参
     * @return 如果成功返回true
     */
    @Override
    default boolean test(T arg) {
        try {
            return testWithException(arg);
        } catch (Throwable e) {
            throw Exceptions.toRuntime(e);
        }
    }

    /**
     * 测试参数（如果可能）异常
     *
     * @param arg 入参
     * @return 如果成功返回true
     * @throws Throwable 异常
     */
    boolean testWithException(T arg) throws Throwable;
}

